<template>
    <a-radio-group v-model:value="size">
        <a-select style="width: 180px" v-model:value="selectBuckle" :options="options" mode="tags" placeholder="选择扣型"
            @change="handleChange"></a-select>
    </a-radio-group>
</template>
<script setup>
import { getOne, queryList } from "@/api/tool/buckleType.js";
const emit = defineEmits(["confirm"]);
const options = ref([]);
const selectBuckle = ref([]);
const props = defineProps({
    buckleType: {
        type: Array,
    },
});
watch(() => props.buckleType, (newValue) => {
    console.log("watch", props.buckleType);
    props.buckleType.forEach((item) => {
        item.label = item.nationalStandard;
        item.value = item.id;
    });
    selectBuckle.value = props.buckleType;
}, { deep: true });

function getList() {
    queryList({ pageSize: 1000, pageNum: 1 }).then((res) => {
        res.content.forEach((item) => {
            item.label = item.nationalStandard;
            item.value = item.id;
        });
        // 去掉空数据
        options.value = res.content.filter(
            (obj) => obj.nationalStandard !== null && obj.nationalStandard !== undefined && obj.nationalStandard !== ""
        );
    });
}

function handleChange() {
    let array = [];
    selectBuckle.value.forEach((item) => {
        getOne(item).then((res) => {
            array.push(res);
        });
    });
    emit("confirm", array);
}
getList();
</script>
